package com.lge.test;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;

public class MyLocation {

	private final Context context;
	private static LocationManager lm;
	private static MyLocationListener locListener;
	
	private double longitude;
	private double latitude;
	
	public MyLocation (Context context) {
		this.context = context;
		
		lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
		locListener = new MyLocationListener();
		startGPS();
	}
	
	public void stopGPS () {
        lm.removeUpdates(locListener);
	}
	
	public void startGPS () {
		lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
	}
	
	public double getLongitude() {
		return longitude;
	}

	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

	public double getLatitude() {
		return latitude;
	}

	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}

	public class MyLocationListener implements LocationListener {

		public void onLocationChanged(Location loc) {
			MyLocation.this.setLatitude(loc.getLatitude());
			MyLocation.this.setLongitude(loc.getLongitude());
		}

		public void onProviderDisabled(String provider) {
			Toast.makeText( MyLocation.this.context, "Gps Disabled",Toast.LENGTH_SHORT ).show();
		}

		public void onProviderEnabled(String provider) {
			// TODO Auto-generated method stub
			
		}

		public void onStatusChanged(String provider, int status, Bundle extras) {
			// TODO Auto-generated method stub
			
		}
	}
}
